﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HVAC
{
	public partial class LaySprinklersLineForm : System.Windows.Forms.Form
	{
		public LaySprinklersLineForm()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
		}

		public LaySprinklersLineForm(UserSetting userSetting)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
		}

		private void rdoLimitNumber_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoLimitNumber.Checked)
			{
				this.rdoLimitDistance.Checked = false;
				this.RdoNumberGroup(true);
				return;
			}
			this.RdoNumberGroup(false);
		}

		private void RdoNumberGroup(bool check)
		{
			this.hytbCount.Enabled = check;
			this.hytbRatio.Enabled = check;
		}

		private void RdoDistanceGroup(bool check)
		{
			this.hytbDistance.Enabled = check;
			this.hytbDistanceSide.Enabled = check;
		}

		private void rdoLimitDistance_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rdoLimitDistance.Checked)
			{
				this.rdoLimitNumber.Checked = false;
				this.RdoDistanceGroup(true);
				return;
			}
			this.RdoDistanceGroup(false);
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			string limitStr = "1";
			if (this.rdoLimitNumber.Checked)
			{
				this.layLineParameter.LimitFlag = 1;
				this.layLineParameter.Count = Convert.ToInt32(this.hytbCount.Text.Trim());
				this.layLineParameter.Ratio = Convert.ToDouble(this.hytbRatio.Text.Trim());
				limitStr = "1";
			}
			else if (this.rdoLimitDistance.Checked)
			{
				this.layLineParameter.LimitFlag = 2;
				this.layLineParameter.Distance = Convert.ToDouble(this.hytbDistance.Text.Trim());
				this.layLineParameter.DistanceSide = Convert.ToDouble(this.hytbDistanceSide.Text.Trim());
				limitStr = "2";
			}
			this.LaySettingWrite(limitStr);
			base.DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void LaySettingWrite(string limitStr)
		{
			this.userSettingS.WriteLaySprinklersLine(this.layLineParameter);
		}

		private void LayAirTerminalLineForm_Load(object sender, EventArgs e)
		{
			this.LaySettingInit();
		}

		private void LaySettingInit()
		{
			this.layLineParameter = this.userSettingS.GetLaySprinklersLine();
			this.hytbCount.Text = this.layLineParameter.Count.ToString();
			this.hytbRatio.Text = this.layLineParameter.Ratio.ToString();
			this.hytbDistance.Text = this.layLineParameter.Distance.ToString();
			this.hytbDistanceSide.Text = this.layLineParameter.DistanceSide.ToString();
			if (this.layLineParameter.LimitFlag.ToString() == "2")
			{
				this.rdoLimitDistance.Checked = true;
				this.rdoLimitNumber.Checked = false;
				return;
			}
			this.rdoLimitNumber.Checked = true;
			this.rdoLimitDistance.Checked = false;
		}

		private HVACUserSetting userSettingS = new HVACUserSetting();

		public LayLineParameter layLineParameter = new LayLineParameter();
	}
}
